<template>
    <div>
        <h3>促销系统</h3>
        <el-table
                :data="tableData.slice((currentPage-1)*PageSize,currentPage*PageSize)" style="width: 100%">
            <!--            包含字段：商品编号、批次、规格、类型、商品名、销售价格、库存数量、当前折扣率-->
            <el-table-column
                    prop="goodscode"
                    label="商品编号">
            </el-table-column>
            <el-table-column
                    prop="goodsbatch"
                    label="批次">
            </el-table-column>
            <el-table-column
                    prop="goodsspecs"
                    label="规格">
            </el-table-column>
            <el-table-column
                    prop="goodstype"
                    label="类型">
            </el-table-column>
            <el-table-column
                    prop="goodsname"
                    label="商品名">
            </el-table-column>
            <el-table-column
                    prop="goodspricce"
                    label="销售价格">
            </el-table-column>
            <el-table-column
                    prop="number"
                    label="库存数量">
            </el-table-column>
<!--            <el-table-column-->
<!--                    prop="discount"-->
<!--                    label="当前折扣率">-->
<!--            </el-table-column>-->

            <el-table-column
                    fixed="right"
                    label="操作">
                <template slot-scope="scope">
                    <el-button @click="choice(scope.row)" type="text" size="small" :disabled="scope.row.goodsstate != 0">选择促销</el-button>
                    <el-button @click="cancel(scope.row)" type="text" size="small" :disabled="scope.row.goodsstate != 1">取消促销</el-button>
                </template>
            </el-table-column>
        </el-table>

        <div class="tabListPage">
            <el-pagination @size-change="handleSizeChange"
                           @current-change="handleCurrentChange"
                           :current-page="currentPage"
                           :page-sizes="pageSizes"
                           :page-size="PageSize" layout="total, sizes, prev, pager, next, jumper"
                           :total="totalCount">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    export default {
        name: "PromotionView",

        data() {
            return {
                currentPage4: 4,
                tableData: [],
                goodsId:'',
                info:'申请促销',
                cancelInfo:'申请取消促销',
                totalCount:null,
                currentPage:1,
                pageSizes:[1,2,3,4,5],
                PageSize:3,

            }
        },

        mounted() {
            this.init()
        },
        methods: {
            //初始化
            init() {
                //查询所有状态为已上架和促销中的商品
                this.$axios.get("/sscsys/seckill/findAll").then(r =>{
                    console.log(r.data)
                    this.tableData = r.data;
                    this.totalCount=r.data.length;
                })
            },

            choice(row) {
                //1、销售价设置折扣
                let that = this
                this.$prompt('请输入折扣', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',

                }).then(({value}) => {
                    //2、发起审核

                    //3、审核成功把状态变为 ‘促销中’，商品在主页面展示

                    console.log(row)
                    console.log(value)
                    let url = "/sscsys/seckill/sellKillGoods/"+row.goodsId+"/"+this.info+"/"+ value;
                    that.$axios.get(url).then(
                        r => {
                            console.log(r.data)
                            this.$message({
                                type: 'info',
                                message: '正在审核'
                            });
                            this.init()

                        }
                    )
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '取消输入'
                    });
                });
            },

            //取消促销
            cancel(row) {
                //1、已经促销的商品的取消促销按钮更改为可以点击状态

                //2、取消审核
                let url = "/sscsys/seckill/cancelSellKill/"+row.goodsId+"/"+this.cancelInfo;
                this.$axios.get(url).then(r =>{
                    console.log(r.data)
                    this.$message({
                        type: 'info',
                        message: '正在审核'
                    });
                    this.init()
                })

                //3、审核通过，状态更改为 ‘已下架’，销售价的折扣更改为 ‘100%’

            },
            //1.分页表格换页方法--开始//
            handleSizeChange(val) {
                this.PageSize=val
                this.currentPage=1
            },
            handleCurrentChange(val) {
                this.currentPage=val
            },
        }
    }
</script>

<style scoped>

</style>